package com.admin.controller;


import com.admin.commen.BaseController;
import com.admin.service.UserService;
import com.fegin.bean.admin.AdminUser;
import com.fegin.bean.common.layuiBean.ResultPage;
import com.fegin.bean.common.layuiBean.VoPage;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2019-01-08
 */
@Controller
@RequestMapping("/admin/user")
public class UserController extends BaseController {

    @Autowired
    UserService userService;

    /**
     * 登陆请求
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    @ResponseBody
    public AdminUser login(String userName,String passWord) {
        return  userService.login(userName,passWord);
    }

    /**
     * 表格查询
     * @param voPage
     * @return
     */
    @RequestMapping(value = "/findUser" )
    @ResponseBody
    public ResultPage<AdminUser> findUser(@RequestBody VoPage voPage, @RequestParam("loginId") Long loginId) {
        return  userService.findUserByPage(voPage,loginId );
    }

    /**
     *  查询分销商
     * @param voPage
     * @return
     */
    @RequestMapping(value = "/findDistributionPeoPleByPage" )
    @ResponseBody
    public ResultPage<AdminUser> findDistributionPeoPleByPage(@RequestBody VoPage voPage) {
        return  userService.findDistributionPeoPleByPage(voPage);
    }



    @RequestMapping(value = "/insertUser", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("button:用户管理添加")
    public Map<String, Object> insertUser(@RequestBody AdminUser user, @RequestParam("roleId") Long roleId, @RequestParam("loginId") Long loginId) {
        return  userService.insertUser(user,roleId,loginId);
    }


    @RequestMapping(value = "/delUser", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("button:用户管理删除")
    public Map<String, Object> delUser(Long userId   ,String userName ) {
        return  userService.delUser(userId,userName  );
    }



}
